import json
from openpyxl import load_workbook
import pathlib
current_py_path=pathlib.Path(__file__).absolute()
excel_file_path='../data/data.xlsx'
print("当前Excel文件路径:",excel_file_path)


# 第一步，获取表格的工作簿对象
wb = load_workbook(excel_file_path)
print(wb)
sheet = wb["Sheet2"]

start_row=2
end_row=892
list_data=[]

with open('../data/data.jsonl','w',encoding="utf-8") as fp:
    for row in range(start_row,end_row+1):
        question=sheet.cell(row=row,column=1).value
        answer=sheet.cell(row=row,column=2).value
        matter=sheet.cell(row=row,column=3).value
        department=sheet.cell(row=row,column=4).value
        json_data={
            "input":question,
            "output":answer,
            "matter":matter,
            "department":department,
            "id":"qa_%03d"%row,
        }
        list_data.append({
            "id":"qa_%03d"%row,
             "split": "train",
             "instance":{
                 "instruction_inputs":json_data["input"],
                 "prompt_labels":json_data["output"]
             }
        })
        str_data=json.dumps(json_data,ensure_ascii=False)
        fp.write(str_data)
        fp.write("\n")

